<?php
define('IN_MEDIA',true);
include('includes/config.php');
include('includes/functions.php');

//header("Cache-Control: private");
//header("Pragma: public");

$id = $_GET['id'];
$type = $_GET['type'];

if ($type == 1) {
header("Cache-Control: private");
header("Pragma: public");
header("Content-Type: application/xml; charset=utf-8");

$asx = '<?xml version="1.0" encoding="utf-8"?>'.
	'<playlist version="1" xmlns="http://xspf.org/ns/0/">'.
	'<trackList>';

$r = $mysql->fetch_array($mysql->query("SELECT m_url, m_title, m_is_local FROM ".$tb_prefix."data WHERE m_id = '".$id."' AND m_type IN ('1','2')"));
	// [Mod] Multi Server Media
	if ($r['m_is_local'])
		$url = $mediaFolder[$r['m_is_local']].'/'.$r['m_url'];
	else {
		$url = $r['m_url'];
		$findme   = 'zippyshare';
		$pos = strpos($url, $findme);
		
		// Note our use of ===.  Simply == would not work as expected
		// because the position of 'a' was the 0th (first) character.
		if ($pos === false) {
			$arr = array("'",'ngamcanh.com');
			$arr_replace = array("%27",'matxac.com');
			$url= str_replace($arr, $arr_replace, m_unhtmlchars($url));
			$url= str_replace("'", "%27", m_unhtmlchars($url));

		} else {
			$temp = explode('.zippyshare.com/v/',$url);
			$temp1 = explode('www',$temp[0]);
			$idzs = trim($temp1[1]);
			$temp2 = explode('/',$temp[1]);
			$zsID = trim($temp2[0]);
			$url = 'http://matxac.com/'.$idzs.'/'.$zsID.'.flv';
			$url= str_replace("'", "%27", m_unhtmlchars($url));

		}
	}				
	// [Mod] Multi Server Media
	$asx .= '<track>'.
		'<Title>'.str_replace("'", " ", m_unhtmlchars($r['m_title'])).'</Title>'.
		'<location>'.$url.'</location>'.
	'</track>';

$asx .= '</trackList>'.
	'</playlist>';
echo $asx;
}
elseif ($type == 2) {
header("Cache-Control: private");
header("Pragma: public");
header("Content-Type: application/xml; charset=utf-8");
$asx = '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/">  
  <channel>  
    <title>MRSS Playlist Playlist</title>';
	$q = $mysql->query("SELECT m_url, m_title, m_is_local FROM ".$tb_prefix."data WHERE m_singer = '".$id."' AND (m_type = 1 OR m_type = 3)");
	$singer_name = m_get_data('SINGER',$id);
	while ($r = $mysql->fetch_array($q)) {
		if ($r['m_is_local'])
			$url = $mediaFolder[$r['m_is_local']].'/'.$r['m_url'];
			else
		$url = $r['m_url'];
		$findme   = 'zippy';
		$pos = strpos($url, $findme);
		
		// Note our use of ===.  Simply == would not work as expected
		// because the position of 'a' was the 0th (first) character.
		if ($pos === false) {
			$arr = array("'",'ngamcanh.com');
			$arr_replace = array("%27",'matxac.com');
			$url= str_replace($arr, $arr_replace, m_unhtmlchars($url));
			$url= str_replace("'", "%27", m_unhtmlchars($url));
		} else {
			$temp = explode('.zippyshare.com/v/',$url);
			$temp1 = explode('www',$temp[0]);
			$idzs = trim($temp1[1]);
			$temp2 = explode('/',$temp[1]);
			$zsID = trim($temp2[0]);
			$url = 'http://matxac.com/'.$idzs.'/'.$zsID.'.flv';
			$url= str_replace("'", "%27", m_unhtmlchars($url));

		}
			$asx .= '<item>'.
				'<title>'.str_replace("'", " ", m_unhtmlchars($r['m_title'])).'</title>'.
				'<media:content url="'.$url.'" />'.
				'</item>';
	}
	$asx .= '</channel>'.
				'</rss>';
			echo $asx;
}
elseif ($type == 3) {
header("Cache-Control: private");
header("Pragma: public");
header("Content-Type: application/xml; charset=utf-8");
$asx = '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/">  
  <channel>  
    <title>MRSS Playlist Playlist</title>';
	$q = $mysql->query("SELECT m_url, m_title, m_singer, m_is_local FROM ".$tb_prefix."data WHERE m_album = '".$id."' AND (m_type = 1 OR m_type = 3)");
	while ($r = $mysql->fetch_array($q)) {
		if ($r['m_is_local'])
			$url = $mediaFolder[$r['m_is_local']].'/'.$r['m_url'];
			else
		$url = $r['m_url'];
		$findme   = 'zippy';
		$pos = strpos($url, $findme);
		
		// Note our use of ===.  Simply == would not work as expected
		// because the position of 'a' was the 0th (first) character.
		if ($pos === false) {
			$arr = array("'",'ngamcanh.com');
			$arr_replace = array("%27",'matxac.com');
			$url= str_replace($arr, $arr_replace, m_unhtmlchars($url));
			$url= str_replace("'", "%27", m_unhtmlchars($url));
		} else {
			$temp = explode('.zippyshare.com/v/',$url);
			$temp1 = explode('www',$temp[0]);
			$idzs = trim($temp1[1]);
			$temp2 = explode('/',$temp[1]);
			$zsID = trim($temp2[0]);
			$url = 'http://matxac.com/'.$idzs.'/'.$zsID.'.flv';
			$url= str_replace("'", "%27", m_unhtmlchars($url));

		}
			$asx .= '<item>'.
				'<title>'.str_replace("'", " ", m_unhtmlchars($r['m_title'])).'</title>'.
				'<media:content url="'.$url.'" />'.
				'</item>';
	}
	$asx .= '</channel>'.
				'</rss>';
			echo $asx;;
}
elseif ($type == 4) {
	
header("Cache-Control: private");
header("Pragma: public");
header("Content-Type: application/xml; charset=utf-8");
$asx = '<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/">  
  <channel>  
    <title>MRSS Playlist Playlist</title>';
	$pl_q = $mysql->query("SELECT playlist_contents FROM ".$tb_prefix."playlist WHERE playlist_id = '".$id."'");
	if ($mysql->num_rows($pl_q)) {
		$pl_r = $mysql->fetch_array($pl_q);
		$playlist = $pl_r['playlist_contents'];
		$q = $mysql->query("SELECT m_url, m_title, m_singer, m_is_local FROM ".$tb_prefix."data WHERE m_id IN (".$playlist.")");
		while ($r = $mysql->fetch_array($q)) {
			if ($r['m_is_local'])
			$url = $mediaFolder[$r['m_is_local']].'/'.$r['m_url'];
			else
		$url = $r['m_url'];
		$findme   = 'zippy';
		$pos = strpos($url, $findme);
		
		// Note our use of ===.  Simply == would not work as expected
		// because the position of 'a' was the 0th (first) character.
		if ($pos === false) {
			$arr = array("'",'ngamcanh.com');
			$arr_replace = array("%27",'matxac.com');
			$url= str_replace($arr, $arr_replace, m_unhtmlchars($url));
			$url= str_replace("'", "%27", m_unhtmlchars($url));
		} else {
			$temp = explode('.zippyshare.com/v/',$url);
			$temp1 = explode('www',$temp[0]);
			$idzs = trim($temp1[1]);
			$temp2 = explode('/',$temp[1]);
			$zsID = trim($temp2[0]);
			$url = 'http://matxac.com/'.$idzs.'/'.$zsID.'.flv';
			$url= str_replace("'", "%27", m_unhtmlchars($url));

		}
			$asx .= '<item>'.
				'<title>'.str_replace("'", " ", m_unhtmlchars($r['m_title'])).'</title>'.
				'<media:content url="'.$url.'" />'.
				'</item>';



		}
	}
			$asx .= '</channel>'.
				'</rss>';
			echo $asx;
	
}

?>